package com.firefly.service.query.cms;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.firefly.dao.dao.cms.po.AdPosPo;
import com.firefly.dao.dao.cms.service.AdPosService;
import com.firefly.dao.assembler.cms.AdPosAssembler;
import com.firefly.dao.dto.cms.AdPosSearchDto;
import com.firefly.dao.vo.CommonListVo;
import com.firefly.dao.vo.cms.AdPosVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 广告位
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/18
 **/
@Service
public class AdPosQuery {
    private final AdPosAssembler adPosAssembler;
    private final AdPosService adPosService;
    @Autowired
    public AdPosQuery(AdPosAssembler adPosAssembler,AdPosService adPosService){
        this.adPosAssembler = adPosAssembler;
        this.adPosService = adPosService;
    }
    // 获取列表
    public CommonListVo getList(AdPosSearchDto request) {
        QueryWrapper<AdPosPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!request.key.isBlank(), "name", request.key).eq("del_flag",0);
        Long count = adPosService.count(queryWrapper);
        queryWrapper.last("limit " + request.offset + "," + request.pageSize).orderByDesc("id");
        List<AdPosPo> list = adPosService.list(queryWrapper);
        CommonListVo result = new CommonListVo();
        result.setCount(count);
        result.setList(adPosAssembler.getVoList(list));
        return result;
    }
    public AdPosVo getDetail(int id) {
        return adPosAssembler.getVo(adPosService.getById(id));
    }
}
